package fr.generali.accueilclient.gwt.client.ui.components.table.columns;

import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

import fr.generali.accueilclient.gwt.client.common.TypedCommand;
import fr.generali.accueilclient.gwt.client.ui.components.table.cells.ClickableLinkCell;

/**
 * Colonne permettant d'ajouter des cellules affichant des liens.<br>
 * 
 * @param <T>
 */
public class ClickableLinkColumn<T> extends MouseEventAwareColumn<T, String> {

    public ClickableLinkColumn(TypedCommand<T> command) {
        super(new ClickableLinkCell(), "", "", command);
    }

    @Override
    public void render(Context context, T object, SafeHtmlBuilder sb) {
        String html =
                        new StringBuilder().append(
                                        "<div style=\"text-align:center;cursor:pointer;text-decoration:underline;\">")
                                        .toString();
        sb.appendHtmlConstant(html);
        super.render(context, object, sb);
        sb.appendHtmlConstant("</div>");
    }

    public void renderWithClickDisabled(Context context, T object, SafeHtmlBuilder sb) {
        String html = new StringBuilder().append("<div style=\"text-align:center;cursor:auto;\">").toString();
        sb.appendHtmlConstant(html);
        super.render(context, object, sb);
        sb.appendHtmlConstant("</div>");
    }

}
